/*==============================================================================
Header Files and Global Defines
==============================================================================*/
#include "resource.h"       //Header File for Resource IDs and Headers

/*==============================================================================
Global Variables
==============================================================================*/
//~~~~~System Variables
    extern float speed_mod;
    struct option
    {
        unsigned int particle_count;
        int particle_speed;
        int first_x;
        int first_y;
        int second_x;
        int second_y;
        int red;
        int green;
        int blue;
    };
    extern struct option options;

/*==============================================================================
FUNCTION PROTOTYPES
==============================================================================*/
//=====Scene Drawing
int DrawScene();

//=====Drawing Functions
void xia_Grid(float VerticleMax, float VerticleMin, float HorizontalMax, 
              float HorizontalMin, float space, float max, float z);

//=====External Functions
//Particle Generator Function
extern void xia_GenUpDown(float limit_x1, float limit_x2, float limit_y1, float limit_y2, float z,
                          float r, float g, float b, float speed_mod);

/*==============================================================================
OPENGL RENDERING SCENE
==============================================================================*/
int DrawScene()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    //glEnable(GL_BLEND);
    glDepthMask(GL_FALSE);
    glEnable(GL_TEXTURE_2D);
//=======Particle Generator
    glPushMatrix();
        xia_GenUpDown(options.first_x*.1, options.second_x*.1, options.first_y*.1, options.second_y*.1, -22.0, 
                      options.red*.01, options.green*.01, options.blue*.01, speed_mod*options.particle_speed*.001);
    glPopMatrix();
    glDepthMask(GL_TRUE);
//=======Grid Background
    glDisable(GL_TEXTURE_2D);
    glPushMatrix();
        glColor3f(0.0,0.25,0.0);
        glTranslatef(0.0,0.0,-2.0);
        xia_Grid(2.6, 2.6, 2.6, 2.6, .18, 2.6, -2.0);
    glPopMatrix();
    //glDisable(GL_BLEND);
    return TRUE;
}

/*==============================================================================
FUNCTIONS
==============================================================================*/
void xia_Grid(float VerticleMax, float VerticleMin, float HorizontalMax, 
              float HorizontalMin, float space, float max, float z)
{
    for(float loop=0.0; loop <= max; loop+=space)
    {
//Horizontal
        glBegin(GL_LINES);
            glVertex3f(-HorizontalMin,loop,z);
            glVertex3f(HorizontalMax,loop,z);
        glEnd();
        glBegin(GL_LINES);
            glVertex3f(HorizontalMin,-loop,z);
            glVertex3f(-HorizontalMax,-loop,z);
        glEnd();
//Verticle
        glBegin(GL_LINES);
            glVertex3f(loop,-VerticleMax,z);
            glVertex3f(loop,VerticleMin,z);
        glEnd();
        glBegin(GL_LINES);
            glVertex3f(-loop,VerticleMax,z);
            glVertex3f(-loop,-VerticleMin,z);
        glEnd();
    }
}
